﻿using System;
using System.Collections.Generic;
using Common;
using DataAccess;
using EntityModel;

namespace Business
{
    public class BusinessBase<T, U>
        where T : EntityBase, new()
        where U : UserModel
    {
        protected RetrieveHelper<T, U> retreiveHelper { get; set; }
        protected ExecuteHelper<T, U> executeHelper { get; set; }

        public BusinessBase()
        {
            retreiveHelper = new RetrieveHelper<T, U>();
            executeHelper = new ExecuteHelper<T, U>();
        }

        public T GetByKey(U userInfo, params object[] keys)
        {
            return this.retreiveHelper.GetByKey(userInfo, keys);
        }

        public List<T> GetAll()
        {
            return this.retreiveHelper.GetAll();
        }

        public Result<T> GetAllPaging(string sortCol, SORT_ORDER sortOrder, Int16 currentPage, Int16 pageNumber)
        {
            return this.retreiveHelper.GetAllPaging(sortCol, sortOrder, currentPage, pageNumber);
        }

        public Result<T> GetAllPaging(Func<T, bool> whereExpression, string sortCol, SORT_ORDER sortOrder, Int16 currentPage, Int16 pageNumber)
        {
            return this.retreiveHelper.GetAllPaging(whereExpression, sortCol, sortOrder, currentPage, pageNumber);
        }

        public T Insert(T entity, U userInfo)
        {
            return this.executeHelper.Insert(entity, userInfo);
        }

        public T Update(T entity, U userInfo)
        {
            return this.executeHelper.Update(entity, userInfo);
        }

        public T Delete(T entity, U userInfo)
        {
            return this.executeHelper.Delete(entity, userInfo);
        }
    }
}
